package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.PsychKnow;
import com.hs.service.PsychKnowService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("psychknow")
public class PsychKnowController {
    @Autowired
    private PsychKnowService psychKnowService;
    @PostMapping
    public R addpsychknow(@RequestBody PsychKnow psychKnow) {
        int i = psychKnowService.addPsychKnow(psychKnow);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @DeleteMapping("{id}")
    public R deletepsychKnow(@PathVariable("id") int id){
        int i = psychKnowService.deletePsychKnow(id);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @PutMapping
    public R updatepsychknow(@RequestBody PsychKnow psychKnow){
        int i = psychKnowService.updatePsychKnow(psychKnow);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @GetMapping("{id}")
    public R getpsychknow(@PathVariable("id") int id){
        PsychKnow psychKnow = psychKnowService.getPsychKnowById(id);
        return R.ok(psychKnow);
    }
    @GetMapping("page")
    public R getpsychknowpage(PsychKnow psychKnow,
                              @RequestParam(required = false,defaultValue = "1") int pageNum,
                              @RequestParam(required = false,defaultValue = "2") int pageSize){
        PageInfo<PsychKnow> psychknowBypage = psychKnowService.getAllPsychKnowByPage(psychKnow,pageNum,pageSize);
        return R.ok(psychknowBypage);
    }
}
